public class BruteForceSolution {
    public int pivotIndex(int[] nums) {
        int sum = 0;
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            int leftSum = sum(nums, 0, i - 1);
            int rightSum = sum(nums, i + 1, n - 1);
            if (leftSum == rightSum) {
                return i;
            }
        }
        return -1;
    }

    public int sum(int[] nums, int i, int j) {//求i到j之间的元素和
        int sum = 0;
        for (int k = i; k <= j; k++) {
            sum += nums[k];
        }
        return sum;
    }
}
